// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:

const { shopData } = require("./gameData");

//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
cc.Class({
    extends: cc.Component,

    properties: {
        menuList:cc.RichText,
        shop:cc.Object
    },

    // LIFE-CYCLE CALLBACKS:

    update () {
        this.showList();
    },

    onEnable () {
        this.showList();
        this.schedule(this.showList,1000);
    },
    onDisable () {
        this.unschedule(this.showList)
    },
    updateSaleList() {
        this.showList();
    },
    showStockPanel(){
        this.node.active = !this.node.active;
    },
    showList(){
        this.menuList.string = ' '
        // let data = shopData.shopList.find(val => {return val.id == shopId});
        let saleText = '';
        if(shop.saleList.length >= 13) {
            shop.saleList.splice(0,shop.saleList.length - 13);
        }
        shop.saleList.forEach(val=>{
            saleText += val+"<br/>";
        })
        this.menuList.string = saleText;
    },
    clearFood(target,id){
        let tmp = this.shop.stock.map(val=>val.id == target.target.parent.id);
        tmp.sort((a,b)=>a.saveTime-b.saveTime);
        tmp.splice(0,1);
    }
    // update (dt) {},
});
